#define _CRT_SECURE_NO_WARNINGS 1


#include<iostream>

using namespace std;

struct TreeNode 
{
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode() 
        :val(0)
        ,left(nullptr)
        ,right(nullptr) 
    { }
    TreeNode(int x) 
        :val(x)
        ,left(nullptr)
        ,right(nullptr) 
    { }
    TreeNode(int x, TreeNode* left, TreeNode* right) 
        :val(x)
        ,left(left)
        ,right(right)
    { }
};

bool Func(TreeNode* root1, TreeNode* root2)
{
    if (root1 == nullptr && root2 == nullptr)
    {
        return true;
    }
    if (root1 == nullptr || root2 == nullptr)
    {
        return false;
    }
    if (root1->val != root2->val)
    {
        return false;
    }
    return Func(root1->left, root2->right) && Func(root1->right, root2->left);
}

bool isSymmetric(TreeNode* root)
{
    return Func(root->left, root->right);
}

int main()
{
    TreeNode* node1 = new TreeNode(1);
    TreeNode* node2 = new TreeNode(2);
    TreeNode* node3 = new TreeNode(2);
    TreeNode* node4 = new TreeNode(3);
    TreeNode* node5 = new TreeNode(4);
    TreeNode* node6 = new TreeNode(4);
    TreeNode* node7 = new TreeNode(3);
    
    node1->left = node2;
    node1->right = node3;
    node2->left = node4;
    node2->right = node5;
    node3->left = node6;
    node3->right = node7;

    cout << isSymmetric(node1) << endl;

	return 0;
}